package com.gogowan.agroenterprise.widget.adapter;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.TextView;


import com.gogowan.agroenterprise.R;

import java.util.List;

public class Base_Adapater extends MyBaseAdapater {
    private Context context;
    private List<?> list;
    private onItemViewClickListener listener;
    private OnItemListener onItemListener;
    private boolean isDelete;
    private String Name="";
    public OnItemListener getOnItemListener() {
        return onItemListener;
    }

    public void setOnItemListener(OnItemListener onItemListener) {
        this.onItemListener = onItemListener;
    }

    public onItemViewClickListener getListener() {
        return listener;
    }

    public void setListener(onItemViewClickListener listener) {
        this.listener = listener;
    }

    public Base_Adapater(Context context, List<?> list, boolean isDelete) {
        this.context = context;
        this.list = list;
        this.isDelete=isDelete;
    }

    public Base_Adapater(Context context, List<?> list) {
        this.context = context;
        this.list = list;
    }
    public void setRightView(boolean isDelete, String Name){
        this.isDelete=isDelete;
        this.Name=Name;
    }
    @Override
    public List<?> getList() {
        return list;
    }

    @Override
    public Context ItemContext() {
        return context;
    }

    @Override
    public int ItemLayout() {
        return R.layout.layout_string_item;
    }

    @Override
    public Object setHoulder(View view) {
        Houlder houlder = new Houlder();
        houlder.Tv1=(TextView)view.findViewById(R.id.Tv1);
        houlder.Tv2=(TextView)view.findViewById(R.id.Tv2);
        return houlder;
    }

    @Override
    public void OnItem(Object o, final int position) {
        Houlder houlder = (Houlder) o;
        String ListenerStr=onItemListener.ItemStr(position);
        if (ListenerStr.contains("</font>")){
            String HtmlStr=ListenerStr.replace("\n","<br/>");
            houlder.Tv1.setText(Html.fromHtml(HtmlStr));
        }else {
            houlder.Tv1.setText(ListenerStr);
        }
        if (!isDelete){
            houlder.Tv2.setVisibility(View.GONE);
        }
        if (Name!=null&&Name.length()>0){
            houlder.Tv2.setText(Name);
        }else {
            houlder.Tv2.setText("删除");
        }
        houlder.Tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onItemViewpositioni(position);
                }
            }
        });
    }

    class Houlder {
        TextView Tv1;
        TextView Tv2;
    }
    public interface OnItemListener{
        String ItemStr(int position);
    }
}
